package com.jiuyou.clientController.base;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginMember;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.sql.SqlUtil;
import com.ruoyi.framework.web.service.MemberTokenService;
import com.ruoyi.order.service.IStoreProductOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.beans.PropertyEditorSupport;
import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * web层通用数据处理
 *
 * @author ruoyi
 */
@Component
public class ClientBaseController extends BaseController
{
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());


    @Autowired
    private MemberTokenService tokenService;
    @Autowired
    private IStoreProductOrderService storeProductOrderService;

    /**
     * 是否新户,传storeId则判断门店，不传则判断平台
     * @param storeId
     * @return
     */
    public boolean isNewUser(Long storeId){
       int num= storeProductOrderService.selectFirstOrder(storeId,getLoginMemberId());
       if(num>0){
           return false;
       }else{
           return true;
       }
    }

    /**
     * 获取用户缓存信息
     */
    public LoginMember getLoginMember()
    {

        return  tokenService.getLoginMember();
    }

    /**
     * 获取登录用户id
     */
    public Long getLoginMemberId()
    {

        return  tokenService.getLoginMemberId();
    }


    public LoginUser getLoginUser()
    {
        return null;
    }

    /**
     * 获取登录用户id
     */
    public Long getUserId()
    {

        return null;
    }

    /**
     * 获取登录部门id
     */
    public Long getDeptId()
    {
        return null;
    }

    /**
     * 获取登录用户名
     */
    public String getUsername()
    {
        return Optional.ofNullable(tokenService.getLoginMember().getMember().getNickName()).orElseThrow(()->new CustomException("无法获取用户"));
    }

}
